package com.jaychen.eureka.result;

import com.jaychen.eureka.enumeration.ServerExceptionCodeEnum;
import java.io.Serializable;

/**
 * @Author Jay Chen
 * @Date 2020/10/27 18:30
 */
public class Result implements Serializable {
    private int code;
    private String msg;
    private Object data;

    public static <T> Result success(T data) {
        return builder().code(ServerExceptionCodeEnum.SERVER_SUCCESS.code).msg(ServerExceptionCodeEnum.SERVER_SUCCESS.msg).data(data).build();
    }

    Result(final int code, final String msg, final Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result.ResultBuilder builder() {
        return new Result.ResultBuilder();
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public Object getData() {
        return this.data;
    }

    public void setCode(final int code) {
        this.code = code;
    }

    public void setMsg(final String msg) {
        this.msg = msg;
    }

    public void setData(final Object data) {
        this.data = data;
    }

    public static class ResultBuilder {
        private int code;
        private String msg;
        private Object data;

        ResultBuilder() {
        }

        public Result.ResultBuilder code(final int code) {
            this.code = code;
            return this;
        }

        public Result.ResultBuilder msg(final String msg) {
            this.msg = msg;
            return this;
        }

        public Result.ResultBuilder data(final Object data) {
            this.data = data;
            return this;
        }

        public Result build() {
            return new Result(this.code, this.msg, this.data);
        }
    }
}
